-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Decouple the Player from the Web Application #13
Conversation
We created a fork of rollup-plugin-web-worker-loader to apply this fix (darionco/rollup-plugin-web-worker-loader#47 (comment)), allowing us to use Terser to minify the build. |
Thanks so much for this, @JoaquinBCh! Testing now. I did have to remove both |
Trying to resolve package dependency issues as discussed on the call today. See PR here: JoaquinBCh#2 |
@JoaquinBCh Hi, is there anything else left to do? I did run test on it successfully with: git remote add JoaquinBCh https://github.com/JoaquinBCh/moq-js.git
git fetch JoaquinBCh
git checkout refactor/decoupling
npm run build
# and also tested
npm run dev |
It looks like the CI errors are just linter complaints. Did we maybe lose track of a config silencing those cases when things shuffled around? |
I fixed some of the linter issues and disabled others, since the idea of this PR isn’t to make extra changes. |
Overview
This pull request decouples the player code (lib directory) from the web application’s build process. Previously, the player was transpiled from TypeScript to JavaScript using tsc and then integrated into the web application where Vite was used to finalize the build. This meant the web application’s build tool needed to handle and bundle the player’s source files.
With these changes, we now produce a standalone build of the player. It can be imported as a package:
or directly included in an HTML page:
Key Changes
1. Switching to Rollup:
To achieve this separation, we moved from using Vite internally for the player to using Rollup. Rollup was chosen because it is commonly used in similar projects (e.g., HLS.js).
2. Handling Web Workers and Audio Worklets:
The main challenge was properly bundling web workers and audio worklets, as they must be included directly in the final build and are imported differently than standard modules. For more context, see this related Vite issue.
Previously, under Vite, workers and worklets were imported using special way:
This approach allowed Vite to understand how to include these resources in the build.
With Rollup, we now leverage the rollup-plugin-web-worker-loader to handle workers and worklets. This plugin has its own conventions for importing such resources, so the imports have been adjusted accordingly.
3. Generating Two Builds (IIFE and ESM):
We now produce two versions of the player:
Example using the IIFE build:
To host this example, we use an Express server configured to send the
"Cross-Origin-Opener-Policy": "same-origin"
and"Cross-Origin-Embedder-Policy": "require-corp"
headers. These headers are required for using SharedArrayBuffer.4. Using the Player in a Web Application: For the integrated web application scenario, you only need to add the player as a dependency in package.json and then import it:
The web application’s bundler can then include the player without needing to rebuild it.
5. Removing the 'publish' Page in the Web App: Since the standalone player build only exposes the player functionality and does not include some additional components (like those used by publish or features from contribute and transport), we have removed the publish page from the web application.